(function(){if(!window["BX"]||window["BX"]["MPF"]||!window["app"])return;var t={},e=function(){var t=function(t){if(BX.type.isNotEmptyString(t)){this.id=t;this.url=t;this.name=t.substr(t.lastIndexOf("/")+1);if(this.name.indexOf("?")>=0)this.name=this.name.substr(0,this.name.indexOf("?"));this.ext=this.name.lastIndexOf(".")>0?this.name.substr(this.name.lastIndexOf(".")+1).toLowerCase():""}else{for(var e in t){if(t.hasOwnProperty(e)){this[e]=t[e]}}}};t.prototype={getErrorText:function(t){return t||BX.message("MPFFileWasNotUploaded")}};return t}(),i=function(){var t=function(t,e,i){this.id=e;this.url=window.location.protocol+"//"+window.location.host+this.urlUpload;this.values={};this.params=i;this.propertyName=this.params["FIELD_NAME"];this.catchUF=BX.delegate(this.catchUF,this);this.parseUF=BX.delegate(this.parseUF,this);this.prepareToSaveUF=BX.delegate(this.prepareToSaveUF,this)};t.prototype={prefixHTMLNode:"disk-attach-",userTypeId:"disk_file",urlUpload:"/bitrix/tools/disk/uf.php?action=uploadFile&ncc=1",uploadBase64:function(t){var e=new window.FileUploadOptions,i=new window.FileTransfer,n=BX.proxy(function(e){e=BX.parseJSON(e.response);if(e==null)o();else this.uploadBase64Response(t,e)},this),o=BX.proxy(function(){this.uploadBase64Failure(t,BX.message("MPFIncorrectResponse"))},this);e.fileKey=this.userTypeId;e.fileName=t.name;e.params={sessid:BX.bitrix_sessid()};e.mimeType="image/jpeg";e.chunkedMode=false;i.upload(t.url,this.url,n,BX.proxy(function(){window.app.BasicAuth({success:BX.proxy(function(s){e.params.sessid=s.sessid_md5;i.upload(t.url,this.url,n,o,e)},this),failure:o})},this),e)},uploadBase64Failure:function(t,e){BX.onCustomEvent(t,"onUploadError",[t.getErrorText(e)])},uploadBase64Response:function(t,e){var i;if(e.status!="success"){i=e["message"];if(!i&&BX.type.isArray(e["errors"])){for(var n=0;n<e["errors"].length;n++){if(e["errors"][n]&&e["errors"][n]["message"]){i=(i||"")+e["errors"][n]["message"]}}}this.uploadBase64Failure(t,i)}else{e=e.data;var o=e["attachId"]||e["id"],s="blank";if(BX.util.in_array(t.ext,["jpg","bmp","jpeg","jpe","gif","png","webp"]))s="img";else if(BX.util.in_array(t.ext,["doc","pdf","ppt","rar","xls","zip"]))s=t.ext;BX.onCustomEvent(t,"onUploadOk",["[DISK FILE ID="+o+"]",{extension:e["ext"],iconUrl:"/bitrix/components/bitrix/mobile.disk.file.detail/images/"+s+".png",previewImageUrl:"",id:o,fileId:o,xmlID:"0",name:e["name"],type:e["ext"],propertyName:this.propertyName,fieldName:this.propertyName+(this.params["MULTIPLE"]=="Y"?"[]":""),fieldValue:o,url:(BX.message("MobileSiteDir")||"/")+"mobile/ajax.php?attachedId="+o+"&action=download&ncc=1&mobile_action=disk_uf_view&filename="+["name"]},this])}},catchUF:function(t,e,i){if(t&&t[this.propertyName]&&t[this.propertyName]["USER_TYPE_ID"]==this.userTypeId&&BX.type.isArray(t[this.propertyName]["VALUE"])){i["uf"]=i["uf"]||{};t=t[this.propertyName];var n=function(){var t="id"+Math.random();while(i["uf"][t])t="id"+Math.random();return t};for(var o=0,s,a,r,l,m,d,h;o<t["VALUE"].length;o++){a=t["VALUE"][o];s=BX(this.prefixHTMLNode+a);r=s&&s.getAttribute("data-bx-title")||"noname";l=r.lastIndexOf(".")>0?r.substr(r.lastIndexOf(".")+1).toLowerCase():"";m="blank";h=n();if(BX.util.in_array(l,["jpg","bmp","jpeg","jpe","gif","png","webp"]))m="img";else if(BX.util.in_array(l,["doc","pdf","ppt","rar","xls","zip"]))m=l;if(s){d={extension:l,iconUrl:"/bitrix/components/bitrix/mobile.disk.file.detail/images/"+m+".png",previewImageUrl:s.getAttribute("data-bx-src")||s.getAttribute("src")||undefined,id:h,fileId:s.getAttribute("bx-attach-file-id"),xmlID:s.getAttribute("bx-attach-xml-id"),name:r,type:l,propertyName:this.propertyName,fieldName:this.propertyName+(this.params["MULTIPLE"]=="Y"?"[]":""),fieldValue:a,url:(BX.message("MobileSiteDir")||"/")+"mobile/ajax.php?attachedId="+a+"&action=download&ncc=1&mobile_action=disk_uf_view&filename="+r};i["uf"][h]=d;e.push(d)}}}},parseUF:function(t,e){if(e&&e.length>0){var i=t.text,n,o;if(BX.type.isNotEmptyString(i)){for(n=0;n<e.length;n++){o=e[n];if(o.propertyName==this.propertyName){if(parseInt(o.fileId)>0){i=i.replace("[DISK FILE ID=n"+o.fileId+"]","[DISK FILE ID="+o.id+"]")}else if(e.length==1&&BX.util.in_array(o.type,["gif","jpg","jpeg","png","jpe","bmp","webp"])){i+="\n[DISK FILE ID="+(o.fieldValue?o.fieldValue:"n"+o.fileId)+"]"}}}}else{var s=null;var a=null;for(n=0;n<e.length;n++){o=e[n];if(o.propertyName===this.propertyName){a="&nbsp;";if(BX.type.isNotEmptyString(o.type)){s=BX.MobileUtils.getType(BX.MobileUtils.getFileMimeType(o.type));if(s==="image"||s==="video"){a="[DISK FILE ID="+(o.fieldValue?o.fieldValue:"n"+o.fileId)+"]"}}}i+=a}}t.text=i}},prepareToSaveUF:function(t,e){if(t.length>0){var i=[];t.forEach(function(t){t["propertyName"]=t["propertyName"]||this.propertyName;t["fieldName"]=t["fieldName"]||t["propertyName"]+(this.params["MULTIPLE"]==="Y"?"[]":"");if(!t["fieldValue"]){var e=t["VALUE"]?t:t["dataAttributes"]&&t["dataAttributes"]["VALUE"]?t["dataAttributes"]:null;if(e){t["name"]=e["NAME"];t["ext"]=t["name"].split(".").pop();t["ext"]=t["ext"]===t["name"]?"":t["ext"];t["id"]=e["ID"];t["fileId"]=e["ID"];t["xmlID"]=0;t["type"]=t["ext"];t["fieldValue"]=e["VALUE"];t["url"]=e["URL"]["URL"]}else if(!t["base64"]){return}}i.push(t)}.bind(this));if(i.length>0){e.add(this,i)}}else{t.push({fieldName:this.propertyName+(this.params["MULTIPLE"]=="Y"?"[]":""),fieldValue:""})}},upload:function(t){var e=t.pop();if(e){var i=BX.proxy(function(o,s){BX.removeCustomEvent(e,"onUploadOk",i);BX.removeCustomEvent(e,"onUploadError",n);for(var a in s){if(s.hasOwnProperty(a)){e[a]=s[a]}}this.upload(t)},this),n=BX.proxy(function(t){BX.removeCustomEvent(e,"onUploadOk",i);BX.removeCustomEvent(e,"onUploadError",n);BX.onCustomEvent(this,"onUploadError",[t])},this);BX.addCustomEvent(e,"onUploadOk",i);BX.addCustomEvent(e,"onUploadError",n);this.uploadBase64(e);return}BX.onCustomEvent(this,"onUploadOk",[])}};return t}(),n=function(){var t=function(){};t.prototype={files:[],queue:{},getId:function(){return"id"+Math.random()},add:function(t,e){if(!t["__queueId"]){t.__queueId=this.getId();t.__onUploadOk=BX.delegate(function(){this.start(t)},this);t.__onUploadError=BX.delegate(this.error,this);BX.addCustomEvent(t,"onUploadOk",t.__onUploadOk);BX.addCustomEvent(t,"onUploadError",t.__onUploadError)}else{var i,n=(this.queue[t.__queueId]||[t,[]])[1];while((i=e.pop())&&i){n.push(i)}e=n}this.queue[t.__queueId]=[t,e]},start:function(t){if(t&&t.__queueId){this.clear(t)}var e;for(var i in this.queue){if(this.queue.hasOwnProperty(i)){e=this.queue[i];delete this.queue[i];if(e[0]&&e[0]["upload"]){e[0]["upload"](e[1])}else{this.start(e[0])}return}}BX.onCustomEvent(this,"onUploadOk",[])},clear:function(t){if(t.__queueId){delete this.queue[t.__queueId];delete t.__queueId;BX.removeCustomEvent(t,"onUploadOk",t.__onUploadOk);BX.removeCustomEvent(t,"onUploadError",t.__onUploadError);delete t.__onUploadOk;delete t.__onUploadError}},error:function(){var t=[],e;for(e in this.queue){if(this.queue.hasOwnProperty(e)){t.push(e)}}while((e=t.pop())&&e)this.clear(this.queue[e]);BX.onCustomEvent(this,"onUploadError",[BX.message("MPFFileWasNotUploaded")])}};return t}(),o=function(){var t=function(t){this.handler=t;this.id=BX.util.getRandomString(8);this.params={placeholder:BX.message("MPFPlaceholder"),onEvent:BX.delegate(this.handleAppCallback,this),onSend:BX.delegate(this.handleAppData,this)}};t.prototype={handleAppData:function(t,i){t=BX.type.isNotEmptyString(t)?{text:t}:BX.type.isPlainObject(t)?t:{};var n=t["attachedFiles"]||[],o=t["text"]||"";if(!i){this.handler.comment.node=null}for(var s=0;s<n.length;s++){n[s]=new e(n[s])}this.stopCheckWriting();BX.onCustomEvent(this,"onFormSubmitted",[o,n])},handleAppFile:function(t,i){if(!i){this.handler.comment.node=null}this.stopCheckWriting();var n=this;window.BXMobileApp.UI.Page.TextPanel.getText(function(i){BX.onCustomEvent(n,"onFileSubmitted",[i,new e(t)])})},handleAppCallback:function(t){if(this.writingParams.lastEvent!=t&&(!t||t["event"]!="removeFocus")){this.writingParams.lastEvent=t;this.writingParams.text+=t.text;this.writingParams["~text"]=t.text;BX.onCustomEvent("main.post.form/text",[t.text]);if(this.writingParams.text.length>4){this.writingParams.text="";this.startCheckWriting()}}},init:function(t,e){t=t||"";this.params.text=t;if(BX.type.isNotEmptyObject(e)&&e.hideForm&&typeof window.BX.MobileUI.TextField["setDefaultParams"]=="function"){window.BX.MobileUI.TextField.setDefaultParams(this.params)}else{window.BX.MobileUI.TextField.show(this.params);if(!BX.type.isNotEmptyObject(e)||!e.clear){BX.onCustomEvent("main.post.form/mobile_simple",[])}}if(BX.type.isNotEmptyString(t)){this.writingParams["~text"]=t}else{this.writingParams["~text"]=""}this.writingParams.text=""},show:function(t){if(BX.type.isString(t)){window.BXMobileApp.UI.Page.TextPanel.setText(t);this.writingParams["~text"]=t}window.BXMobileApp.UI.Page.TextPanel.focus()},clear:function(){this.writingParams.text="";this.writingParams["~text"]="";window.BXMPage.TextPanel.clear()},writingParams:{lastFired:0,lastEvent:null,frequency:1e4,text:"","~text":""},stopCheckWriting:function(){this.writingParams.text=""},startCheckWriting:function(){var t=new Date;if(t-this.writingParams.lastFired>this.writingParams.frequency){BX.onCustomEvent(this,"onUserIsWriting",[this]);this.writingParams.lastFired=t}},showWait:function(){window.BXMobileApp.UI.Page.TextPanel.showLoading(true)},closeWait:function(){window.BXMobileApp.UI.Page.TextPanel.showLoading(false)}};return t}(),s=function(){var t=function(t,e){this.handler=t;this.formSettings={attachButton:{items:this.initFiles(e["CID"])},attachFileSettings:{resize:[40,1,1,1e3,1e3,0,2,false,true,false,null,0],sendLocalFileMethod:"base64",saveToPhotoAlbum:true},attachedFiles:[],extraData:{},mentionButton:{dataSource:{return_full_mode:"YES",outsection:"NO",okname:BX.message("MPFButtonSend"),cancelname:BX.message("MPFButtonCancel"),multiple:"NO",alphabet_index:"YES",url:BX.message("MobileSiteDir")+"mobile/index.php?mobile_action=get_user_list&use_name_format=Y"}},smileButton:{},message:{text:""},okButton:{callback:BX.delegate(this.applyExtendedForm,this),name:BX.message("MPFButtonSend")},cancelButton:{callback:BX.delegate(this.cancelExtendedForm,this),name:BX.message("MPFButtonCancel")}}};t.prototype={initFiles:function(t){this.controllers={};if(!t||typeof t!=="object")return[];var e,i=[],n;for(e in t){if(t.hasOwnProperty(e)){if(t[e]["USER_TYPE_ID"]=="disk_file"){n={id:"disk",name:BX.message("MPFPostFormDisk"),dataSource:{multiple:"NO",url:BX.message("SITE_DIR")+"mobile/?mobile_action=disk_folder_list&type=user&path=%2F&entityId="+BX.message("USER_ID")}};n.dataSource[window["platform"]=="ios"?"table_settings":"TABLE_SETTINGS"]={searchField:"YES",showtitle:"YES",modal:"YES",name:BX.message("MPFPostFormDiskTitle")};i.push(n)}}}if(i.length>0){i.push({id:"mediateka",name:BX.message("MPFPostFormPhotoGallery")});i.push({id:"camera",name:BX.message("MPFPostFormPhotoCamera")})}return i},applyExtendedForm:function(t){this.stopCheckWriting();t.text=t.text||"";t.attachedFiles=t.attachedFiles||[];for(var i=0;i<t.attachedFiles.length;i++){t.attachedFiles[i]=new e(t.attachedFiles[i])}t.extraData=t.extraData||{};BX.onCustomEvent(this,"onApplyComment",[t,t.attachedFiles]);BX.onCustomEvent(this,"onFormSubmitted",[t.text,t.attachedFiles,t.extraData])},cancelExtendedForm:function(){BX.onCustomEvent(this,"onCancelComment",[]);this.stopCheckWriting()},show:function(t,e){var i=document.createElement("textarea");i.innerHTML=t;this.formSettings.message={text:i.value};i.remove();this.formSettings.attachedFiles=[];this.formSettings.extraData={};if(e){BX.onCustomEvent(this,"onEditCommentUF",[e["UF"],this.formSettings.attachedFiles,this.formSettings.extraData]);BX.onCustomEvent(this,"onEditCommentFiles",[e["FILES"],this.formSettings.attachedFiles,this.formSettings.extraData])}window.app.exec("showPostForm",this.formSettings)},clear:function(){this.writingParams.text="";this.writingParams["~text"]=""},writingParams:{lastFired:0,lastEvent:null,frequency:1e4,text:""},stopCheckWriting:function(){this.writingParams.text=""},startCheckWriting:function(){var t=new Date;if(t-this.writingParams.lastFired>this.writingParams.frequency){this.writingParams.lastFired=t}},showWait:function(){},closeWait:function(){}};return t}();BX.MPF=function(){var e=function(e){if(!window.app.enableInVersion(4))throw this.errors["error00"];if(t[e["formId"]])t[e["formId"]].destroy();this.form=BX(e["formId"]);if(!this.form)throw this.errors["error01"];this.id=this.form.id;this.forumContext=e.forumContext||"";BX.hide(this.form);document.body.appendChild(this.form);this.text=this.form.elements[e.text.name];if(!this.text){this.text=BX.create("INPUT",{props:{type:"hidden",name:e.text.name,value:""}});this.form.appendChild(this.text)}this.block=BX.create("DIV",{className:"bx-additional-block-data"});this.form.appendChild(this.block);this.simpleForm=new o(this);this.extendedForm=new s(this,e);this.currentForm=null;this.uniqueId=BX.util.getRandomString(8);t[this.id]=this;this.initEvents();this.controllers={};this.initControllers(e["CID"]);BX.onCustomEvent(window,"onMPFIsInitialized",[this])};e.prototype={errors:{error00:"BX.MPL: Mobile Application is obsolete.",error01:"BX.MPL: form does not exist."},initEvents:function(){BX.addCustomEvent(this.simpleForm,"onFormSubmitted",BX.delegate(this.submitExtended,this));BX.addCustomEvent(this.simpleForm,"onUserIsWriting",BX.delegate(this.writing,this));BX.addCustomEvent(this.extendedForm,"onFormSubmitted",BX.delegate(this.submitExtended,this));BX.addCustomEvent(this.extendedForm,"onCancelComment",this.cancel.bind(this))},initControllers:function(t){if(t||typeof t=="object"){var e,n=false;for(e in t){if(t.hasOwnProperty(e)){if(t[e]["USER_TYPE_ID"]=="disk_file"){this.controllers[e]=new i(this,e,t[e]);if(!n){BX.addCustomEvent(this,"onExtendedCheckUpload",this.controllers[e]["prepareToSaveUF"]);BX.addCustomEvent(this,"onExtendedCheckData",this.controllers[e]["parseUF"]);n=true}BX.addCustomEvent(this.extendedForm,"onEditCommentUF",this.controllers[e]["catchUF"]);BX.addCustomEvent(this.extendedForm,"onApplyComment",this.controllers[e]["parseUF"])}}}}},destroy:function(){BX.remove(this.form);BX.onCustomEvent(this.handler,"onMPFHasBeenDestroyed",[this.id,t[this.id],this]);t[this.id]=null},writing:function(){BX.onCustomEvent(this,"onMPFUserIsWriting",[this.comment])},setForm:function(t){this.currentForm=t===true?this.extendedForm:this.simpleForm},init:function(t,e){this.comment=t;this.setForm(false);this.simpleForm.init(t.text,{hideForm:BX.type.isNotEmptyString(this.forumContext)&&this.forumContext.toLowerCase()=="task",clear:BX.type.isNotEmptyObject(e)&&BX.type.isBoolean(e.clear)&&e.clear})},show:function(t,e){BX.onCustomEvent(this,"onShow",[this,t]);this.comment=t;this.setForm(e);this.currentForm.show(t.text,t.attachments)},clear:function(){if(this.currentForm!==null){this.currentForm.clear()}},submitBase64:function(t,e){var i={filesToPost:false};BX.onCustomEvent(this,"onBase64Submitted",[e,i]);if(i["filesToPost"]!==false){BX.onCustomEvent(this.comment,"onStart",[this.comment,t,[e]]);BX.addCustomEvent(e,"onUploadOk",BX.proxy(function(e,i){this.submit(BX.type.isNotEmptyString(t)?t:e,[i])},this));BX.addCustomEvent(e,"onUploadError",BX.proxy(this.error,this));BX.onCustomEvent(e,"onUploadStart",[e])}else{this.cancel()}},submitExtended:function(t,e,i){if(!(BX.type.isNotEmptyString(t)||BX.type.isArray(e)&&e.length>0)){this.cancel();return}if(typeof i!="undefined"&&typeof i["uf"]!="undefined"){for(var n=0,o,s;n<e.length;n++){if(e[n]&&e[n]["id"]&&i["uf"][e[n]["id"]]){for(s in i["uf"][e[n]["id"]]){if(i["uf"][e[n]["id"]].hasOwnProperty(s)){if(!e[n][s]){e[n][s]=i["uf"][e[n]["id"]][s]}}}e[n]["id"]=i["uf"][e[n]["id"]]["fieldValue"]}}}var a={attachments:e,uploadTasks:[],taskIdList:[]};this.processAttachments(a).then(function(){this.setForm(false);this.clear();this.comment.text=t;this.text.value=this.comment.getText();this.comment.attachments=e;this.comment.extraData=i;BXMobileApp.onCustomEvent("Comments.UploadQueue::setItem",{commentNodeId:this.comment.node.id,commentVirtualId:a.commentVirtualId,formId:this.form.id,formUniqueId:this.uniqueId,entityId:this.comment.id[0],text:t,attachments:BX.type.isArray(a.attachments)?a.attachments:[],taskIdList:BX.type.isArray(a.taskIdList)?a.taskIdList:[],extraData:typeof i!="undefined"?i:{}},true)}.bind(this));BX.onCustomEvent(this.comment,"onStart",[this.comment,t,e])},cancel:function(){this.setForm(false);this.clear();BX.onCustomEvent(this.comment,"onCancel",[this.comment])},error:function(t){this.setForm(false);this.clear();BX.onCustomEvent(this.comment,"onError",[this.comment,t])},addComment:function(t){var e={text:t.text},i=t.attachments;var o=new n;BX.onCustomEvent(this,"onExtendedCheckUpload",[i,o]);BX.onCustomEvent(this,"onExtendedCheckData",[e,i]);if(BX.type.isNotEmptyString(e.text))this.submit(e.text,i);else this.cancel()},addError:function(t,e){this.cancel()},submit:function(t,e,i){this.setForm(false);this.clear();this.comment.text=t;this.text.value=this.comment.getText();this.comment.attachments=e;this.comment.extraData=i;BX.onCustomEvent(this.comment,"onSubmit",[this.comment])},getForm:function(t){return BX.ajax.prepareForm(this.form,t).data},showWait:function(){if(this.currentForm!==null)this.currentForm.showWait()},closeWait:function(){if(this.currentForm!==null)this.currentForm.closeWait()},processAttachments:function(t){var e=new Promise(function(e,i){t.commentVirtualId=parseInt(Math.random()*1e5);if(BX.type.isNotEmptyObject(t)&&BX.type.isArray(t.attachments)&&t.attachments.length>0){var n=null,o=null,s=null;for(var a=0;a<t.attachments.length;a++){o=t.attachments[a];if(o&&o.url&&o.url.match(/^file:\/\//)){n="commentTask_"+parseInt(Math.random()*1e5);s=BX.MobileUtils.getFileMimeType(o.type);t.uploadTasks.push({taskId:n,type:o.type,mimeType:s,folderId:parseInt(BX.message("MOBILE_EXT_UTILS_USER_FOLDER_FOR_SAVED_FILES")),params:{commentVirtualId:t.commentVirtualId},name:typeof BX.MobileUtils.getUploadFilename==="function"?BX.MobileUtils.getUploadFilename(o.name,o.type):o.name,url:o.url,previewUrl:o.previewUrl?o.previewUrl:null,resize:BX.MobileUtils.getResizeOptions(o.type)});t.taskIdList.push(n);delete t.attachments[a]}}t.attachments=t.attachments.filter(function(t){return t});if(t.uploadTasks.length>0){BXMobileApp.onCustomEvent("onFileUploadTaskReceived",{files:t.uploadTasks},true)}e()}else{e()}}.bind(this));e.catch(function(t){console.error(t)});return e}};return e}();BX.MPF.createInstance=function(e){if(!t[e["formId"]])new BX.MPF(e);return t[e["formId"]]};BX.MPF.getInstance=function(e){return t[e]};BX.MPF.onUploadQueueReady=function(e){var i=null;for(var n in t){if(n==e.formId){i=BX.MPF.getInstance(e.formId);if(i&&i.uniqueId&&e.formUniqueId&&i.uniqueId==e.formUniqueId&&i.comment.id[0]==e.entityId){i.addComment(e.commentData);break}}}};BX.MPF.onUploadQueueError=function(e){var i=null;for(var n in t){if(n==e.formId){i=BX.MPF.getInstance(e.formId);if(i.comment.id[0]==e.entityId){i.addError(e.commentData,e.errorText);BX.onCustomEvent(window,"OnUploadQueueError",[e]);break}}}};BX.onCustomEvent(window,"main.post.form/mobile",["mobile"]);BXMobileApp.addCustomEvent("Comments.UploadQueue::ready",BX.MPF.onUploadQueueReady);BXMobileApp.addCustomEvent("Comments.UploadQueue::error",BX.MPF.onUploadQueueError)})();
//# sourceMappingURL=script.map.js